****************************************
***DOUBLE LASSO FOR CONTROL SELECTION***
****************************************
**
clear all

**** Install packages ***
*ssc install pdslasso
*ssc install lassopack

********************
*Set Person Working*
*Change this to your name!!!!!
********************
*global carolina 0
*global emily 1

global emily 1
global carolina 0

*********************
*Load Files*
*********************
if $emily ==1  {
*Emily's Computer*
cap cd "~/Dropbox/SourceContent/Data/Study"
global out "../../Results/Balance/"
} 

*Carolina's Computer*
if $carolina ==0  {
cap cd "E:\Dropbox\Carolina-Emily-Project\Data\Study"
global out "..\..\Results\Source\"

}


use 2_clean_data, replace


*********************************
***Create Variables and Format***
*********************************

//List Predictors
global covar2 i.gender i.race i.agegroup i.educgroup i.workgroup i.democrat ///
	i.voted2016 i.candidate2016 i.pre_immlevel_raw5 i.pre_gun_index_raw5 i.pre_abortion_index_raw5 ///
	i.pre_tax_index_raw5 i.pre_health_index_raw5 i.freq_facebook i.freq_twitter ///
	i.freq_tv i.freq_newspaper i.freq_fox i.freq_msnbc i.freq_breitbart ///
	i.freq_buzzfeed i.freq_nytimes i.fan_obama i.fan_trump i.fan_lebronjames ///
	i.fan_billgates i.fan_ellendegeneres i.fan_taylorswift i.fan_kimkardashian ///
	i.georegion i.born_in_us weather_clickcount i.topissue_type 

	
/*Order or Treatment Groups*
5 7 6 8 1 3 2 4 9 10
*/

gen group1=treatment==5 | treatment==7 
gen group2=treatment==6 | treatment==8 
gen group3=treatment==1 | treatment==3 
gen group4=treatment==2 | treatment==4 


gen president=treatment==1 | treatment==2 | treatment==5 | treatment==6
gen actor=treatment==3 | treatment==4 | treatment==7 | treatment==8

*****************************
*****************************
*****************************
global party0 "Republicans"
global party1 "Democrats"
global var0 "ln(Probability Anti-Immigrant)"
global var1 "ln(Probability Pro-Immigrant)"
global rule0 "\toprule"
global rule1 "\midrule"
global dir0 "anti"
global dir1 "pro"

****************************************
****************************************
reg president  $covar2 if sample==1

rlasso president  $covar2 if (group1==1) & recruit==0 & sample==1, robust
rlasso president  $covar2 if (group2==1) & recruit==0 & sample==1, robust
rlasso president  $covar2 if (group3==1) & recruit==0 & sample==1, robust
rlasso president  $covar2 if (group4==1) & recruit==0 & sample==1, robust 
 
rlasso president  $covar2 if (group1==1) & recruit==1 & sample==1, robust
rlasso president  $covar2 if (group2==1) & recruit==1 & sample==1, robust
rlasso president  $covar2 if (group3==1) & recruit==1 & sample==1, robust
rlasso president  $covar2 if (group4==1) & recruit==1 & sample==1, robust 

****For Republicans****
rlasso ln1_prob_index_anti  $covar2 if  recruit==0 & sample==1, robust
display `e(selected)'

***Update Variables**
gen age55_64=0
replace age55_64=1 if agegroup==5
label var age55_64 "Age: 55-64"

gen candidate16_hillary=0
replace  candidate16_hillary=1 if candidate2016==2
label var candidate16_hillary "Voted for Clinton 2016"

gen candidate16_other=0
replace  candidate16_other=1 if  candidate2016==3
label var candidate16_other "Voted for Other 2016"

gen immlevel_decrease=0
replace immlevel_decrease=1 if pre_immlevel_raw5==5
label var immlevel_decrease "Pre: Immigration Decrease"

gen gun_lessstrict=0 
replace gun_lessstrict=1 if pre_gun_index_raw5==5
label var gun_lessstrict "Gun Control: Less Strict"

gen abortion_illegal=0
replace abortion_illegal=1 if pre_abortion_index_raw5==5
label var abortion_illegal "Abortion: Should be Illegal"

gen health_notgvt=0 
replace health_notgvt=1 if pre_health_index_raw5==5
label var health_notgvt "Healthcare: Not Government Responsibility"

gen occ_twitter=0
replace occ_twitter=1 if freq_twitter==1
label var occ_twitter "Twitter: Occasionally"

gen occ_buzzfeed=0
replace occ_buzzfeed=1 if freq_buzzfeed==1
label var occ_buzzfeed "Buzzfeed: Occasionally"

gen lebronfan=0
replace lebronfan=1 if fan_lebronjames ==2
label var lebronfan "Lebron James Fan"

gen taylorfan=0
replace taylorfan=1 if  fan_taylorswift==2
label var taylorfan "Taylor Swift Fan"

gen bgatesfan=0
replace bgatesfan=1 if  fan_billgates==2
label var bgatesfan "Bill Gates Fan"

gen obama_neutral=0
replace obama_neutral=1 if fan_obama==1
label var obama_neutral "Obama No Opinion"

gen topissue_health=0
replace topissue_health=1 if topissue_type==4
label var topissue_health "Top Vote Issue: Healthcare"

global lasso0 hispanic age55_64 candidate16_hillary candidate16_other ///
	immlevel_decrease gun_lessstrict abortion_illegal health_notgvt ///
	occ_twitter occ_buzzfeed trumpfan lebronfan taylorfan bgatesfan ///
	obamafan obama_neutral topissue_health 



****For Democrats *****
rlasso ln1_prob_index_anti  $covar2 if  recruit==1 & sample==1, robust


*** Update Variables ****
gen age35_44=0
replace age35_44=1 if agegroup==3
label var age35_44 "Age: 35-44"

gen age45_54=0
replace age45_54=1 if agegroup==4
label var age45_54 "Age: 45-54"

gen hsdegree=0
replace hsdegree=1 if educgroup==3
label var hsdegree "High School Degree"

gen immlevel_same=0
replace immlevel_same=1 if pre_immlevel_raw5==3
label var immlevel_same "Pre: Immigration Same Level"

gen health_neutral=0 
replace health_neutral=1 if pre_health_index_raw5==3
label var health_neutral "Healthcare: No Opinion"

gen gun_same=0 
replace gun_same=1 if pre_gun_index_raw5==3
label var gun_same "Gun Control: Keep Same"

gen abortion_partlegal=0
replace abortion_partlegal=1 if pre_abortion_index_raw5==3
label var abortion_partlegal "Abortion: Legal in Some Cases"

gen tax_toohigh=0
replace tax_toohigh=1 if  pre_tax_index_raw5==5
label var tax_toohigh "Taxes: Too High"

gen daily_newspaper=0
replace daily_newspaper=1 if freq_newspaper==3
label var daily_newspaper "Newspaper: Daily"

gen daily_tv=0
replace daily_tv=1 if freq_tv==3
label var daily_tv "TV: Daily"

gen occ_tv=0
replace occ_tv=1 if freq_tv==1
label var occ_tv "TV: Occasionally"
 
gen week_breitbart=0
replace week_breitbart=1 if freq_breitbart==2
label var week_breitbart "Breitbart: Weekly"
 
gen daily_breitbart=0
replace daily_breitbart=1 if freq_breitbart==3
label var daily_breitbart "Breitbart: Daily"
 
gen lebron_neutral=0
replace lebron_neutral=1 if  fan_lebronjames==1
label var lebron_neutral "Lebron James Neutral"

gen trump_neutral=0
replace trump_neutral=1 if fan_trump==1
label var trump_neutral "Trump Neutral"

gen topissue_tax=0
replace topissue_tax=1 if topissue_type==5
label var topissue_tax "Top Vote Issue: Taxes"

label var west "West Region"


global lasso1 black hispanic age35_44 age45_54 hsdegree ///
	candidate16_hillary immlevel_decrease immlevel_same ///
	gun_same gun_lessstrict abortion_partlegal abortion_illegal tax_toohigh ///
	health_neutral health_notgvt i.freq_nytimes ///
	daily_tv occ_tv daily_newspaper i.freq_fox week_breitbart ///
	daily_breitbart occ_buzzfeed ///
	lebron_neutral obamafan trump_neutral trumpfan west topissue_tax 


drop group* president actor

save 2B_clean_data, replace

